package com.jdy.haoduoaiteacher.widget;

import android.app.Activity;
import android.content.Context;
import android.graphics.drawable.ColorDrawable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup.LayoutParams;
import android.widget.PopupWindow;

import com.jdy.haoduoaiteacher.util.Tools;
import com.ycsj.goldmedalnewconcept.R;

public class PopDeleteWindow extends PopupWindow {
  private View conentView;

  public interface OnMenuClickListener {
    void onClickShare();

    void onClickDelete();

    void onClickCancel();
  }

  private OnMenuClickListener mOnMenuClickListener;

  public void setOnMenuClickListener(OnMenuClickListener mOnMenuClickListener) {
    this.mOnMenuClickListener = mOnMenuClickListener;
  }

  public PopDeleteWindow(final Activity context) {
    LayoutInflater inflater = (LayoutInflater) context
        .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    conentView = inflater.inflate(R.layout.popup_window2, null);
    int h = context.getWindowManager().getDefaultDisplay().getHeight();
    int w = context.getWindowManager().getDefaultDisplay().getWidth();
    // 设置SelectPicPopupWindow的View
    this.setContentView(conentView);
    // 设置SelectPicPopupWindow弹出窗体的宽
    this.setWidth(Tools.getPixelByDip(context,120));
    // 设置SelectPicPopupWindow弹出窗体的高
    this.setHeight(LayoutParams.WRAP_CONTENT);
    // 设置SelectPicPopupWindow弹出窗体可点击
    this.setFocusable(true);
    this.setOutsideTouchable(true);
    // 刷新状态
    this.update();
    // 实例化一个ColorDrawable颜色为半透明
    ColorDrawable dw = new ColorDrawable(0000000000);
    // 点back键和其他地方使其消失,设置了这个才能触发OnDismisslistener ，设置其他控件变化等操作
    this.setBackgroundDrawable(dw);
    // mPopupWindow.setAnimationStyle(android.R.style.Animation_Dialog);
    // 设置SelectPicPopupWindow弹出窗体动画效果
    this.setAnimationStyle(R.style.AnimationPreview);
//    conentView.findViewById(R.id.view_h11).setVisibility(View.GONE);
//    conentView.findViewById(R.id.view_h22).setVisibility(View.GONE);
//      conentView.findViewById(R.id.tv_share).setVisibility(View.GONE);



    conentView.findViewById(R.id.tv_share).setOnClickListener(
        new OnClickListener() {

          @Override
          public void onClick(View arg0) {
            // do something you need here
            PopDeleteWindow.this.dismiss();
            if (mOnMenuClickListener != null) {
              mOnMenuClickListener.onClickShare();
            }
          }
        });
      conentView.findViewById(R.id.tv_cancel).setVisibility(View.GONE);
    conentView.findViewById(R.id.tv_cancel).setOnClickListener(
        new OnClickListener() {

          @Override
          public void onClick(View arg0) {
            // do something before signing out
            // context.finish();
            PopDeleteWindow.this.dismiss();

            if (mOnMenuClickListener != null) {
              mOnMenuClickListener.onClickCancel();
            }
          }
        });

//    conentView.findViewById(R.id.tv_delete).setBackgroundResource(R.drawable.round_corner_with_blue_stroke);
    //android:background="@drawable/"
    conentView.findViewById(R.id.tv_delete).setOnClickListener(
        new OnClickListener() {

          @Override
          public void onClick(View arg0) {
            // do something you need here
            // context.finish();
            PopDeleteWindow.this.dismiss();
            if (mOnMenuClickListener != null) {
              mOnMenuClickListener.onClickDelete();
            }
          }
        });
  }

  /**
   * 显示popupWindow
   * 
   * @param parent
   */
  public void showPopupWindow(View parent) {
    if (!this.isShowing()) {
      // 以下拉方式显示popupwindow
      this.showAsDropDown(parent, parent.getLayoutParams().width / 2, 5);
    } else {
      this.dismiss();
    }
  }
}
